<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            width: 100px;
            height: 100px;
            background-color: red;
        }
    </style>
</head>

<body>
    <div>
        111
    </div>
    <button>按钮</button>
</body>
<script>
    //1.修改样式
    const box = document.querySelector('div');
    // console.log(box);
    //2.通过事件修改样式
    const bu = document.querySelector('button');
    console.log(bu);
    let b = false;
    bu.addEventListener('click', function () {
        console.log('texts');
        if (b) {
            box.style.backgroundColor = 'blue';
            b = false;
            console.log(b);

        } else {
            box.style.backgroundColor = 'pink';
            b = true;
            console.log(b);

        }
    })
</script>

</html>